<script>
import {ElMessage} from "element-plus";
import axios  from "axios";
export default {
  data() {
    return {
      //分页
      currentPage: 1,
      pageSize: 5,
      pageInfo: {},

      formLabelWidth: '200px',
      queryFrm: {                    // 查询对象
        Complaint_id: "",
      },
      formShow:{},    //显示申诉信息
      formUpdate:{},  // 修改申诉信息对象
      appealData: [], // 申诉信息列表
      dialogUpdateFormVisible:false,
      handler:"",
      currentAdminName:''
    }
  },
  methods:{
    //分页
    LoadStuPageData() {
      this.$http.get("http://localhost:8080/appeal/page", {
        params: {
          page: this.currentPage,
          size: this.pageSize
        }
      }).then((res) => {
        this.pageInfo = res.data;
        this.tableData = res.data.list;
        console.log(this.tableData);
      }).catch((err) => {
        console.log(err);
      });
    },

    btnDel(complaint_id){
      console.log(complaint_id);
      this.$http.get("http://localhost:8080/appeal/del/"+complaint_id).then((res)=>{
        console.log(res.data);
        if (res.data===1){
          console.log("删除成功!");
          ElMessage({
            message: '删除成功!',
            type: 'success',
          })
          this.LoadAppealData();
        }else {
          ElMessage({
            message: '删除失败!',
            type: 'warning',
          })
          console.log("删除失败!");
        }
      }).catch((err)=>{})
    },
    btnShowUpdate(Complaints_id){            // 打开修改对话框,并回显数据
      console.log(Complaints_id);
      this.formUpdate = {...Complaints_id,operator:this.currentAdminName};
      this.dialogUpdateFormVisible = true;
    },
    btnUpdateAppealInfo(){               // 提交修改以后得数据
      console.log(this.formUpdate);
      this.$http.post("http://localhost:8080/appeal/updata",this.formUpdate).then((res)=>{
        if (res.data===1){
          console.log("修改成功!");
          ElMessage({
            message: '修改成功!',
            type: 'success',
          })
          this.LoadAppealData();
          this.formUpdate={};
          this.dialogUpdateFormVisible = false;
        }else {
          console.log("修改失败!");
          ElMessage({
            message: '修改失败!',
            type: 'warning',
          })
        }
      }).catch((err)=>{})
    },
    onSubmit(){
      console.log(this.queryFrm);
      this.LoadAppealData();
    },
    LoadAppealData(){
      this.$http.get("http://localhost:8080/appeal/querydata",{params:{
          Complaint_id:this.queryFrm.Complaint_id,
        }}).then((res)=>{
        this.appealData = res.data;
        console.log(res.data);
      }).catch(function(err){
        console.log(err);
      })
    },
    LoadAppealInfoData(){
      this.$http.get("http://localhost:8080/appeal/data").then((res)=>{
        this.appealData = res.data;
        console.log(res.data)
      }).catch(function (err){
        console.log(err);
      })
    },
  },
  mounted() {
    this.LoadStuPageData();  //分页
    this.currentAdminName = localStorage.getItem('adminName')
    console.log(this.currentAdminName)
    this.LoadAppealInfoData();
  }
}
</script>

<template>
  <el-card style="max-width: 100%">
    <template #header>
      <div class="card-header">
        <span>申诉管理</span>
      </div>
    </template>
    <el-form :inline="true" :model="queryFrm" class="demo-form-inline">
      <el-form-item label="申诉单查询">
        <el-input v-model="queryFrm.Complaint_id" placeholder="查询" clearable />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
      </el-form-item>
    </el-form>

    <el-table :data="appealData" stripe style="width: 100%">
      <el-table-column  label="申诉编号" prop="complaint_id" width="120" />
      <el-table-column prop="order_id" label="订单编号" width="120" />
      <el-table-column prop="complaint_people" label="申诉人" width="80"/>
      <el-table-column prop="complaint_content" label="申诉内容" />
      <el-table-column prop="complaint_time" label="申诉时间" />
      <el-table-column prop="complaint_result" label="申诉结果" />
      <el-table-column prop="operator" label="处理人" />
      <el-table-column fixed="right" label="操作" width="180">
        <template #default="scope">
          <el-button  type="info" size="small" @click="btnShowUpdate(scope.row)">
            点击处理
          </el-button>
          <el-popconfirm
              confirm-button-text="是的"
              cancel-button-text="取消"
              icon-color="#626AEF"
              title="确定要删除这个申诉单吗?"
              @confirm="btnDel(scope.row.complaint_id)"
          >
            <template #reference>
              <el-button link type="danger" size="small" >
                删除
              </el-button>
            </template>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>
  </el-card>

  <el-dialog v-model="dialogUpdateFormVisible" title="申诉审核" width="600">
    <el-form :model="formUpdate">
      <el-form-item label="申诉编号" :label-width="formLabelWidth">
        {{formUpdate.complaint_id}}
      </el-form-item>
      <el-form-item label="申诉人" :label-width="formLabelWidth">
        {{formUpdate.complaint_people}}
      </el-form-item>
      <el-form-item label="申诉内容" :label-width="formLabelWidth">
        {{formUpdate.complaint_content}}
      </el-form-item>
      <el-form-item label="处理结果" :label-width="formLabelWidth">
        <el-input v-model="formUpdate.complaint_result" autocomplete="off" />
      </el-form-item>
      <el-form-item label="处理人" :label-width="formLabelWidth">
        {{ this.currentAdminName }}
      </el-form-item>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="dialogUpdateFormVisible = false">取消</el-button>
        <el-button type="primary" @click="btnUpdateAppealInfo">
          修改
        </el-button>
      </div>
    </template>
  </el-dialog>

  <el-pagination
      v-model:current-page="currentPage"
      v-model:page-size="pageSize"
      :page-sizes="[3, 4, 5, 6]"
      layout="total, sizes, prev, pager, next, jumper"
      :total="pageInfo.total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
  />

</template>

<style scoped>

</style>